﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AMS.DataAccess.Trademark.Interfaces;
using AMS.DataAccess.Trademark.BO;
using AMS.DataAccess.BO;
using AMS.DataAccess.Interfaces;

public partial class Cases_EditCustomerContactor : BaseWorkPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Utils.ParseIntQueryString(Request, "caseid", ref caseId))
        {
            GlobalTransfer.RedirectToErrorPage("参数不正确");
            return;
        }

        if (!IsPostBack)
        {
            DoDataBind();
        }
    }

    #region Properties
    int caseId;
    int CustomerID
    {
        get { return ViewState["CustomerID"] == null ? 0 : (int)ViewState["CustomerID"]; }
        set { ViewState["CustomerID"] = value; }
    }
    #endregion

    void DoDataBind()
    {
        ICaseBasicInfoManager caseMgr = ManagerFactory.CreateCaseBasicInfoManager();
        ICustomerManager cusMgr = ManagerFactory.CreateCustomerManager();

        CaseDisplayInfo caseInfo = caseMgr.GetCaseBasicInfo(CallContext, caseId);
        BindTitle(caseInfo);
        ucCustomer.BindCustomer(caseInfo.CustomerID);
        CustomerID = caseInfo.CustomerID;
    }

    void BindTitle(CaseDisplayInfo caseInfo)
    {
        lblTitle.Text = CaseUtils.FormatCaseTitle(caseInfo);
    }

    protected void btnSave_Click(object sender, EventArgs e)
    {
        ICustomerManager cusMgr = ManagerFactory.CreateCustomerManager();
        CustomerInfo customer = cusMgr.GetCustomer(CustomerID);
        if (customer != null)
        {
            if (ucCustomer.GetCustomer(customer))
            {
                cusMgr.UpdateCustomer(CallContext, customer);
                Server.Transfer("EditCaseContactor.aspx" + Request.Url.Query);
            }
        }
        else
        {
            MsgInfo("客户信息不存在，可能已经被删除。");
        }
    }
}
